//引入http模块
const http = require("http");
//创建服务
const server = http.createServer((req, res) => {
    //设置编码格式
    res.setHeader("Content-Type", "text/html;charset=utf-8");
   //设置返回的响应数据
    res.end("hello world 你好世界!");
});
//服务监听
server.listen(8181);

/* 
访问方式:
    1. http://localhost:端口号/地址    只能本机访问  本机
    2. http://127.0.0.1:8989/地址      只能本机访问  本机
    3. http:// 192.168.12.108:端口/地址   : cmd =>ipconfig : 局域网的IP地址   局域网能相互访问

*/

/* 
注意: 
    1.一个端口只能启动一个服务
        netstat -ano  查看端口的使用情况   查找pid  ,通过任务管理器结束对应端口的进程
    2.一旦修改了服务器,服务器需要重启
    3.写中文,设置编码格式  setHeader("Content-Type","text/html;charset=utf-8")  
    4.chrom 浏览器 预留一些端口,不可用,但也不会报错
    1 --- tcpmux 
7 --- echo 
9 --- discard 
11 --- systat 
13 --- daytime 
15 --- netstat 
17 --- qotd 
19 --- chargen 
20 --- ftp data 
21 --- ftp access 
22 --- ssh 
23 --- telnet 
25 --- smtp 
37 --- time 
42 --- name 
43 --- nicname 
53 --- domain 
77 --- priv-rjs 
79 --- finger 
87 --- ttylink 
95 --- supdup 
101 --- hostriame 
102 --- iso-tsap 
103 --- gppitnp 
104 --- acr-nema 
109 --- pop2 
110 --- pop3 
111 --- sunrpc 
113 --- auth 
115 --- sftp 
117 --- uucp-path 
119 --- nntp 
123 --- NTP 
135 --- loc-srv /epmap 
139 --- netbios 
143 --- imap2 
179 --- BGP 
389 --- ldap 
465 --- smtp+ssl 
512 --- print / exec 
513 --- login 
514 --- shell 
515 --- printer 
526 --- tempo 
530 --- courier 
531 --- chat 
532 --- netnews 
540 --- uucp 
556 --- remotefs 
563 --- nntp+ssl 
587 --- stmp? 
601 --- ?? 
636 --- ldap+ssl 
993 --- ldap+ssl 
995 --- pop3+ssl 
2049 --- nfs 
3659 --- apple-sasl / PasswordServer 
4045 --- lockd 
6000 --- X11 
6665 --- Alternate IRC [Apple addition] 
6666 --- Alternate IRC [Apple addition] 
6667 --- Standard IRC [Apple addition] 
6668 --- Alternate IRC [Apple addition] 
6669 --- Alternate IRC [Apple addition]

*/